<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title><?php echo ((isset($title) && ($title !== ""))?($title):get_system_config("system_name")); ?></title>
		<link href="/Public/Ins/css/bootstrap.min.css" rel="stylesheet">
		<link href="/Public/Ins/font-awesome/css/font-awesome.css" rel="stylesheet">
		<link href="/Public/Ins/css/animate.css" rel="stylesheet">
		<link href="/Public/Ins/css/plugins/toastr/toastr.min.css" rel="stylesheet">
		<link href="/Public/Ins/css/plugins/gritter/jquery.gritter.css" />
		<?php if(!empty($plugin["jquery-ui"])): ?><link rel="stylesheet" href="/Public/Ins/css/plugins/jQueryUI/jquery-ui-1.10.4.custom.min.css" />
	<link rel="stylesheet" href="/Public/Ins/css/plugins/nouslider/jquery.nouislider.css" rel="stylesheet"><?php endif; ?>

	<link rel="stylesheet" href="/Public/Ins/css/plugins/date-time/bootstrap-datetimepicker.css" />


		<link href="/Public/Ins/css/style.css" rel="stylesheet">
		<link href="/Public/Ins/css/xiaowei.css" rel="stylesheet">
		<link href="/Public/Ins/css/nprogress.css" rel="stylesheet">
		<script src="/Public/Ins/js/nprogress.js"></script>
		<link rel="stylesheet" href="/Public/Ins/css/plugins/nouslider/jquery.nouislider.css" rel="stylesheet"><link rel="stylesheet" href="/Public/Ins/css/plugins/date-time/bootstrap-datetimepicker.css" />
		
	</head>
	<script type="text/javascript">
	var upload_url = "<?php echo U('upload');?>";
	var del_url = "<?php echo U('del_file');?>";
	var app_path = "";
	var cookie_prefix = "<?php echo C('COOKIE_PREFIX');?>";
	var link_select = "<?php echo U('Popup/link_select');?>";
	
</script>

	<body class="<?php echo (CONTROLLER_NAME); ?>">
		<div class="shade"></div>
		<div class="form-group hidden" id="img_upload_container">
			<div id="img_upload">上传</div>
		</div>
		<nav class="navbar navbar-default row" role="navigation" id="top_menu">
			<!-- Brand and toggle get grouped for better mobile display -->
			<div class="navbar-header">
				<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse-6">
					<span class="sr-only">Toggle navigation</span>
					<i class="fa fa-bars fa-lg"></i>
				</button>
				<div class="hidden-xs">
					&nbsp;
				</div>
				<a href="<?php echo U('index/index');?>" class="navbar-brand"><?php echo get_system_config("system_name");?></a>
			</div>
			<!-- Collect the nav links, forms, and other content for toggling -->
			<div class="collapse navbar-collapse" id="navbar-collapse-6">
				<ul class="nav navbar-nav navbar-right">
					<?php if(is_array($top_menu)): foreach($top_menu as $key=>$top_menu_vo): ?><a class="nav-app" href="#" url="<?php echo (get_nav_url($top_menu_vo['url'])); ?>" node="<?php echo ($top_menu_vo["id"]); ?>" onclick="click_top_menu(this)" ><i class="<?php echo ($top_menu_vo["icon"]); ?>"></i><?php echo ($top_menu_vo["name"]); ?>
						<?php if(!empty($badge_count[$top_menu_vo['id']])){ $html=''; $html='<span class="label label-danger">'.$badge_count[$top_menu_vo['id']].'</span>'; echo $html; } ?></a><?php endforeach; endif; ?>
					<a class="nav-app btn-danger" href="<?php echo U('public/logout');?>"><i class="fa fa-sign-out"></i>退出</a>
				</ul>
			</div><!-- /.navbar-collapse -->
		</nav>
		<div id="wrapper">
			<div class="sidebar navbar-static-side" id="sidebar">
				<div id="user_info" class="text-center hidden-xs"  >
					<span >当前用户：<?php echo (session('user_name')); ?></span>
				</div>
				<div id="nav_head" class="text-center" onclick="toggle_left_menu()">
					<span class="menu-text"><?php echo ($top_menu_name); ?></span>
					<b id="left_menu_icon" class="fa fa-angle-down pull-right"></b>
				</div>
				<?php echo W('Sidebar/left',array('tree'=>$left_menu,'badge_count'=>$badge_count));?>
			</div>
			<div id="page-wrapper" class="gray-bg">
				<div class="row wrapper border-bottom gray-bg">
					<div class="breadcrumbs" id="breadcrumbs">
						<ul class="breadcrumb">
							<li>
								<i class="fa fa-home home-icon"></i>
								<a href="/">Home</a>
							</li>
							<li>
								<?php echo ($top_menu_name); ?>
							</li>
						</ul><!-- .breadcrumb -->
					</div>
				</div>
				<div class="wrapper wrapper-content">
					
   <link href="/sap/demo.css" rel="stylesheet" type="text/css" />
    <script src="/sap/scripts/boot.js" type="text/javascript"></script>



        <legend><span>入库</span></legend>
        <div  id='fm1'>
        <div class="fieldset-body">
        供应商代码:  <div class="mini-autocomplete" style="width:250px;"  popupWidth="400" textField="cardcode" valueField="cardname"  id='CardCode' name='CardCode'
        url="/Warehouse/getSupplier" value="" text=""  onvaluechanged="" >     
        <div property="columns">
            <div header="客户代码" field="cardcode" width="30"></div>
            <div header="客户名称" field="cardname"></div>
        </div>
    </div>
    <!--  <span>添加日期：</span>
		<input id="start" class="mini-datepicker"  format="yyyy-MM-dd "  showTime="true" valueType='string' value="<?php echo date('Y-m-d',time()-86400*7)?>"/>
		<input id="end" class="mini-datepicker"  format="yyyy-MM-dd "  showTime="true" valueType='string' value="<?php echo date('Y-m-d ')?>" /> -->
		
	入库类型:<input id="s_type" class="mini-combobox" style="width:150px;" textField="text" valueField="id" emptyText="请选择..."
    data="[{id:'GIN1',text:'盘盈调拨入库'},{id:'OR',text:'退货入库'}]"  required="true" allowInput="true" showNullItem="true" nullItemText="请选择..."/>
	<br/>
    <!-- <a class="mini-button" onclick="search()" enabled="" id='query-bt'  style="margin-top: 5px">&nbsp;&nbsp;查询&nbsp;&nbsp;</a> -->
 
  
   
    <div id="tabs1" class="mini-tabs" activeIndex="0" style="width:100%;margin-top: 5px;overflow:auto;" plain="false"
    buttons="#tabsButtons"
>
    <div title="物料" >
   
   <div id="datagrid1" class="mini-datagrid" style="height:430px;width: 100%;" 
        url="/goods/queryItemByCode" idField="id"
        allowResize="true" 
        allowCellEdit="true" allowCellSelect="true" multiSelect="true"
        allowCellValid="true" oncellvalidation="" 
    >
    
        <div property="columns">
           
             <div field="Item"  headerAlign="center"  >物料号
                <input property="editor" class="mini-textbox" style="width:100%;" />
            </div>    
            
             <div field="ItemName"  headerAlign="center" width='300px' >物料名称
                <input property="editor" class="mini-textbox" style="width:100%;" />
            </div>   
            <div field="U_TypeOption"  headerAlign="center" width='80px' >颜色
                <input property="editor" class="mini-textbox" style="width:100%;" />
            </div> 
            
              
            <div field="ItemCount"  headerAlign="center"  >数量
                <input property="editor" class="mini-textbox" style="width:100%;" />
                 <input property="editor" class="mini-spinner"  minValue="0" maxValue="999999" />
            </div>        
            
            <div field="Sprice"  headerAlign="center"  >价格
                <input property="editor" class="mini-spinner"  minValue="0" maxValue="9999999" />
            </div> 
          
        </div>
    </div>
    
    </div>
    <!-- <div title="Tab2" iconCls="" >
        2
    </div> -->
</div>
<br/>
	备注: <input id="textarea1" name="Area" class="mini-textarea" style="width: 300px;height: 100px" />
  <div id='editForm1'>
    <br/>
    <a class="mini-button" onclick="onButtonEdit()" enabled="" id='query-bt' >&nbsp;&nbsp;添加物料&nbsp;&nbsp;</a>
    <a class="mini-button" onclick="save()" enabled="" id='query-bt' >&nbsp;&nbsp;保存&nbsp;&nbsp;</a>
  </div>
</body>
<script type="text/javascript">
        mini.parse();
        var grid = mini.get("datagrid1");
        grid.on("drawcell", function (e) {
        var record = e.record,
        column = e.column,
        field = e.field,
        value = e.value;

            //格式化日期
            if (field == "U_FroTime"||field=='U_ToTime') {
                if (mini.isDate(value)) e.cellHtml = mini.formatDate(value, "yyyy-MM-dd HH:mm:ss");
				
            }

          

        });

       

        function onButtonEdit(e) {
            var btnEdit = this;
            mini.open({
                url:  "/sap/goods_select_sap.php",
                title: "选择物料",
                width: 650,
                height: 380,
                ondestroy: function (action) {
                    //if (action == "close") return false;
                    if (action == "ok") {
                        var iframe = this.getIFrameEl();
                        var data = iframe.contentWindow.GetData();
                        data = mini.clone(data);    //必须
                        if (data) {
                        	data.Item=data.catid;
                        	data.ItemName=data.name;
                        	data.Sprice=data.price;
                        	data.ItemCount = 0;
                            grid.addRow(data, 0);
                           
                        }
                    }

                }
            });
        }

        function save() {
        	var data = grid.getChanges();
        	if(data.length==0){
        		mini.alert('请添加物料');
        		return ;
        	}
			for(var i=0;i<data.length;i++){
				if(data[i].ItemCount<=0){
					mini.alert('['+data[i].ItemName+']'+'  数量不能小于等于0');
					return ;
				}
			}
			

           var form = new mini.Form("#fm1");
           var json = mini.encode(data); 
           var type = mini.get('s_type').getText();
           if(type==''){
        	   mini.alert('请选择入库类型');
        	   return ;
           }
           
           var CardCode = mini.get('CardCode').getText();
			 var CardName = mini.get('CardCode').getValue();
			 if(type=='退货入库'){
		     if(CardCode==''){
		    	 mini.alert('供应商代码不能为空');
		    	 return ; 
		     }
			 }
           
           var remark = mini.get('textarea1').getValue();
           
             mini.mask({
                el: document.body,
                cls: 'mini-mask-loading',
                html: '保存中...'
            }); 
             var type = mini.get('s_type').getValue(); //type 改成获取代码code
            $.ajax({
                url: "/warehouse/saveenter",
                data: {CardName:CardName,CardCode:CardCode, data: json,type:type,remark:remark},
                type: "post",
                dataType:'json',
                success: function (data) {
                   if(data.Success){
                	    mini.unmask(document.body);
						mini.alert(data.Description);
						search();
						return ;
                   }else{
                	   mini.unmask(document.body);
                	   mini.alert(data.Description);
                       }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                }
            });
        }


    </script>
    
				</div>
			</div>
		</div>
		<iframe src="<?php echo U('push/client');?>" class="push" id="push"></iframe>
		<!-- Mainly scripts -->
		<script src="/Public/Ins/js/jquery-2.1.1.js"></script>
		<script src="/Public/Ins/js/bootstrap.min.js"></script>
		<script src="/Public/Ins/js/plugins/metisMenu/jquery.metisMenu.js"></script>
		<script src="/Public/Ins/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
		

		<!-- Custom and plugin javascript -->
		<script src="/Public/Ins/js/inspinia.js"></script>
		<script src="/Public/Ins/js/common.js"></script>
		<script src="/Public/Ins/js/plugins/pace/pace.min.js"></script>
		<?php if(!empty($plugin["jquery-ui"])): ?><script src="/Public/Ins/js/plugins/jquery-ui/jquery-ui.min.js"></script>
	<script src="/Public/Ins/js/plugins/nouslider/jquery.nouislider.min.js"></script><?php endif; ?>

	<script src="/Public/Ins/js/plugins/date-time/moment-with-locales.js"></script>
	<script src="/Public/Ins/js/plugins/date-time/bootstrap-datetimepicker.js"></script>


<?php if(!empty($plugin["uploader"])): ?><script type="text/javascript" src="/Public/Ins/js/plugins/plupload/plupload.full.min.js"></script>
	<?php if(empty($plugin["auth"])): ?><script type="text/javascript" src="/Public/Ins/js/plugins/plupload/plupload.setting.js"></script><?php endif; endif; ?>

<?php if(!empty($plugin["editor"])): if(empty($plugin["uploader"])): ?><script type="text/javascript" src="/Public/Ins/js/plugins/plupload/plupload.full.min.js"></script><?php endif; ?>
	<script type="text/javascript" src="/Public/Ins/js/plugins/tinymce/tinymce.min.js"></script>
	<script type="text/javascript" src="/Public/Ins/js/plugins/tinymce/tinymce.setting.js"></script><?php endif; ?>

<?php if(!empty($plugin["baidu_map"])): ?><script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=EE6745c36d96321e90b7015f3de4a4ee"></script><?php endif; ?>

<script src="/Public/Ins/js/plugins/toastr/toastr.min.js"></script>
<script src="/Public/Ins/js/plugins/gritter/jquery.gritter.min.js"></script>
<script src="/Public/Ins/js/plugins/bootbox/bootbox.min.js"></script>

<script type="text/javascript">
	$(document).ready(function() {
		<?php if(!empty($plugin["date"])): ?>$('.input-date').datetimepicker({
			format : 'YYYY-MM-DD',
			locale : 'zh-cn',
			ignoreReadonly : true,
			widgetPositioning : {
				horizontal : 'auto',
				vertical : 'bottom'
			},
		});
		
		$(".input-daterange input").datetimepicker({
			format : "YYYY-MM-DD",
			locale : 'zh-cn',
			showTodayButton : true,
			showClose : true,
			ignoreReadonly : true,
			widgetPositioning : {
				horizontal : 'auto',
				vertical : 'bottom'
			},
		});

		$("#start_date").on("dp.change", function(e) {
			if ($("#end_date").length > 0) {
				$('#end_date').data("DateTimePicker").minDate(e.date);
			}
		});
		
		$("#end_date").on("dp.change", function(e) {
			if ($("#start_date").length > 0) {
				$('#start_date').data("DateTimePicker").maxDate(e.date);
			}
		});

		$(".input-date-time").datetimepicker({
			format : 'YYYY-MM-DD HH:mm',
			locale : 'zh-cn',
			sideBySide : true,
			showTodayButton : true,
			showClose : true,
			ignoreReadonly : true,
			widgetPositioning : {
				horizontal : 'auto',
				vertical : 'bottom'
			},
		});<?php endif; ?>		 
	}); 
</script>
		
	</body>
</html>